#include "stm32f4xx_hal.h"
#include "stm32f4xx_ll_rcc.h"
#include "stdio.h"

#include "DevicesADC.h"
#include "DevicesDelay.h"
#include "DevicesQueue.h"
#include "DevicesMem.h"
#include "DevicesTime.h"
#include "DevicesTimer.h"
#include "DevicesSPIFlash.h"
#include "DevicesSoftTimer.h"
#include "DevicesKey.h"
#include "DevicesWatchDog.h"
#include "DevicesRandom.h"
#include "DevicesCRC.h"
#include "DevicesUart.h"
#include "DevicesPower.h"
#include "DevicesLed.h"

#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"

#include "taskSoftTimer.h"
#include "taskKey.h"
#include "taskMessageRead.h"
#include "taskSystem.h"


/* 系统任务句柄 */
TaskHandle_t g_TaskSystemHand = NULL;


void vSystemHardInit(void)
{
    vHardCRCInit();

    vRandHardInit();

    vMemInit();
    enumQueueInit();

    vLedInit();

    vKeyInit();

    vSPIFlashInit();
}

void vTaskSystem(void *pvParameters)
{
    printf("FreeRTOS start runing...\r\n");


    xTaskCreate(vTaskMessageRead,        "Message Read",       1024, NULL, configMAX_PRIORITIES - 7, &g_TaskMessageReadHand);

    xTaskCreate(vTaskKey,                "Key",                512,  NULL, configMAX_PRIORITIES - 9, &g_TaskKeyHand);


    vSystemHardInit();

    printf("SystemInit succeed.\r\n");


    while (1)
    {
        vLedOpen(LED_ALL);
        vTaskDelay(500 / portTICK_RATE_MS);

        vLedClose(LED_ALL);
        vTaskDelay(500 / portTICK_RATE_MS);

        vWatchdogReload();
    }
}
